﻿using CampusTrade.Pojo;
using CampusTrade.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CampusTrade.Controller
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly UserService userService;
        public UserController(UserService userService)
        {
            this.userService = userService;
        }

        /**
         * 根据id获取用户
         */
        [HttpGet("getById/{id}")]
        public User getUserInfoById(long id)
        {
            return userService.selectUserById(id);
        }
        /**
         * 根据openid获取用户
         */
        [HttpGet("getByOpenId/{openId}")]
        public User getUserInfoByOpenId(string openId)
        {
            return userService.selectUserByOpenId(openId);
        }
        /**
         * 注册用户
         */
        [HttpPost("addUser")]
        public long addUserInfo(User user)
        {
            return userService.addUser(user);
        }
        /**
         * 更新用户
         */
        [HttpPut("updateUser")]
        public int updateUserInfo(User user)
        {
            return userService.updateUserInfo(user);
        }
        /**
         * 删除用户
         */
        [HttpDelete("delUser/{id}")]
        public int deleteUserInfo(long id)
        {
            return userService.deleteUser(id);
        }
    }
}
